{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #Create Target Array in the Given Order"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Easy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #array #simulation"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #数组 #模拟"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: createTargetArray"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #按既定顺序创建目标数组"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p>给你两个整数数组 <code>nums</code> 和 <code>index</code>。你需要按照以下规则创建目标数组：</p>\n",
    "\n",
    "<ul>\n",
    "\t<li>目标数组 <code>target</code> 最初为空。</li>\n",
    "\t<li>按从左到右的顺序依次读取 <code>nums[i]</code> 和 <code>index[i]</code>，在 <code>target</code> 数组中的下标 <code>index[i]</code> 处插入值 <code>nums[i]</code> 。</li>\n",
    "\t<li>重复上一步，直到在 <code>nums</code> 和 <code>index</code> 中都没有要读取的元素。</li>\n",
    "</ul>\n",
    "\n",
    "<p>请你返回目标数组。</p>\n",
    "\n",
    "<p>题目保证数字插入位置总是存在。</p>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>示例 1：</strong></p>\n",
    "\n",
    "<pre><strong>输入：</strong>nums = [0,1,2,3,4], index = [0,1,2,2,1]\n",
    "<strong>输出：</strong>[0,4,1,3,2]\n",
    "<strong>解释：</strong>\n",
    "nums       index     target\n",
    "0            0        [0]\n",
    "1            1        [0,1]\n",
    "2            2        [0,1,2]\n",
    "3            2        [0,1,3,2]\n",
    "4            1        [0,4,1,3,2]\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 2：</strong></p>\n",
    "\n",
    "<pre><strong>输入：</strong>nums = [1,2,3,4,0], index = [0,1,2,3,0]\n",
    "<strong>输出：</strong>[0,1,2,3,4]\n",
    "<strong>解释：</strong>\n",
    "nums       index     target\n",
    "1            0        [1]\n",
    "2            1        [1,2]\n",
    "3            2        [1,2,3]\n",
    "4            3        [1,2,3,4]\n",
    "0            0        [0,1,2,3,4]\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 3：</strong></p>\n",
    "\n",
    "<pre><strong>输入：</strong>nums = [1], index = [0]\n",
    "<strong>输出：</strong>[1]\n",
    "</pre>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>提示：</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>1 &lt;= nums.length, index.length &lt;= 100</code></li>\n",
    "\t<li><code>nums.length == index.length</code></li>\n",
    "\t<li><code>0 &lt;= nums[i] &lt;= 100</code></li>\n",
    "\t<li><code>0 &lt;= index[i] &lt;= i</code></li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [create-target-array-in-the-given-order](https://leetcode.cn/problems/create-target-array-in-the-given-order/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [create-target-array-in-the-given-order](https://leetcode.cn/problems/create-target-array-in-the-given-order/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['[0,1,2,3,4]\\n[0,1,2,2,1]', '[1,2,3,4,0]\\n[0,1,2,3,0]', '[1]\\n[0]']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def createTargetArray(self, nums: List[int], index: List[int]) -> List[int]:\n",
    "        result = []\n",
    "        for i in range(len(nums)):\n",
    "            result = result[:index[i]] + [nums[i]] + result[index[i]:]\n",
    "        return result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def createTargetArray(self, nums: List[int], index: List[int]) -> List[int]:\n",
    "        ans = []\n",
    "        for a, b in zip(index, nums):\n",
    "            ans.insert(a,b)\n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def createTargetArray(self, nums: List[int], index: List[int]) -> List[int]:\n",
    "        target=[nums[0]]\n",
    "        for i in range(1,len(nums)):\n",
    "            idx=index[i]\n",
    "            n=nums[i]\n",
    "            temp=target[idx:]\n",
    "            if idx>=len(target):\n",
    "                target.append(n)\n",
    "            else:\n",
    "                target[idx]=n\n",
    "            target=target[:idx+1]+temp\n",
    "        return target"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "#     def createTargetArray(self, nums: List[int], index: List[int]) -> List[int]:\n",
    "#         u=[]\n",
    "#         for i in range(len(nums)):\n",
    "#             u.insert(index[i],nums[i])\n",
    "#         return class Solution:\n",
    "    def createTargetArray(self, nums: List[int], index: List[int]) -> List[int]:\n",
    "        sol = []\n",
    "        for v,i in zip(nums, index):\n",
    "            sol.insert(i, v)\n",
    "        return sol"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def createTargetArray(self, nums: List[int], index: List[int]) -> List[int]:\n",
    "        result = []\n",
    "        for i in range(len(nums)):\n",
    "            result.insert(index[i], nums[i])\n",
    "        return result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def createTargetArray(self, nums: List[int], index: List[int]) -> List[int]:\n",
    "        target = []\n",
    "        for i in range(len(nums)):\n",
    "            target.insert(index[i], nums[i])\n",
    "        return target"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def createTargetArray(self, nums: List[int], index: List[int]) -> List[int]:\n",
    "        res = []\n",
    "        for i in range(len(nums)):\n",
    "            res.insert(index[i], nums[i])\n",
    "        return res\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def createTargetArray(self, nums: List[int], index: List[int]) -> List[int]:\n",
    "        u=[]\n",
    "        for i in range(len(nums)):\n",
    "            u.insert(index[i],nums[i])\n",
    "        return u"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def createTargetArray(self, nums: List[int], index: List[int]) -> List[int]:\n",
    "        target = []\n",
    "        for x, i in zip(nums, index):\n",
    "            target.insert(i, x)\n",
    "        return target"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def createTargetArray(self, nums: List[int], index: List[int]) -> List[int]:\n",
    "        ans = []\n",
    "        for i in range(len(nums)):\n",
    "            ans.insert(index[i], nums[i])\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def createTargetArray(self, nums: List[int], index: List[int]) -> List[int]:\n",
    "        target = []\n",
    "        for i in range(len(nums)):\n",
    "            target.insert(index[i], nums[i])\n",
    "        return target"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def createTargetArray(self, nums: List[int], index: List[int]) -> List[int]:\n",
    "        target = []\n",
    "        for i in range(len(index)):\n",
    "            target.insert(index[i], nums[i])\n",
    "        return target"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def createTargetArray(self, nums: List[int], index: List[int]) -> List[int]:\n",
    "        a=[]\n",
    "        for i in range(len(nums)):\n",
    "            a.insert(index[i],nums[i])\n",
    "        return a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def createTargetArray(self, nums: list[int], index: list[int]) -> list[int]:\n",
    "        target: list[int] = []\n",
    "        for i in range(len(nums)):\n",
    "            target.insert(index[i], nums[i])\n",
    "        return target\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def createTargetArray(self, nums: List[int], index: List[int]) -> List[int]:\n",
    "        ans = []\n",
    "        for i in range(len(nums)):\n",
    "            ans.insert(index[i], nums[i])\n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def createTargetArray(self, nums: List[int], index: List[int]) -> List[int]:\n",
    "        target = []\n",
    "        for i in range(len(index)):\n",
    "            target.insert(index[i],nums[i])\n",
    "        return target"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def createTargetArray(self, nums: List[int], index: List[int]) -> List[int]:\n",
    "        target=[]\n",
    "        # for i,j in zip(index,nums):\n",
    "        #     target.insert(i,j)\n",
    "        # return target\n",
    "        for i,j in zip(index,nums):\n",
    "            target=target[:i]+[j]+target[i:]\n",
    "        return target"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def createTargetArray(self, nums: List[int], index: List[int]) -> List[int]:\n",
    "        ret = []\n",
    "        for i in range(len(nums)):\n",
    "            ret.insert(index[i], nums[i])\n",
    "        return ret\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def createTargetArray(self, nums: List[int], index: List[int]) -> List[int]:\n",
    "        l=[]\n",
    "        for i in range(len(nums)):\n",
    "            l.insert(index[i],nums[i])\n",
    "        return l"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def createTargetArray(self, nums: List[int], index: List[int]) -> List[int]:\n",
    "        target = []\n",
    "        target_len = len(index)\n",
    "        if len(nums) < target_len:\n",
    "            return \n",
    "        for i in range(target_len):\n",
    "            target.insert(index[i], nums[i])\n",
    "        return target"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def createTargetArray(self, nums: List[int], index: List[int]) -> List[int]:\n",
    "        n = len(nums) \n",
    "        target = [-1] * n \n",
    "        for x, idx in zip(nums,index):\n",
    "            if target[idx] == -1:\n",
    "                target[idx]= x\n",
    "            else:\n",
    "                pre = x\n",
    "                j = idx \n",
    "                while target[j] != -1:\n",
    "                    nxt = target[j]\n",
    "                    target[j] = pre \n",
    "                    pre = nxt \n",
    "                    j+=1 \n",
    "                target[j] = pre \n",
    "        return target \n",
    "         \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def createTargetArray(self, nums: List[int], index: List[int]) -> List[int]:\n",
    "        target = list()\n",
    "        for i in range(len(index)):\n",
    "            target.insert(index[i],nums[i])\n",
    "        return target"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def createTargetArray(self, nums: List[int], index: List[int]) -> List[int]:\n",
    "        target = []\n",
    "        n = len(index)\n",
    "        for i in range(n):\n",
    "            target.insert(index[i], nums[i])\n",
    "        return target\n",
    "        '''\n",
    "        target = []\n",
    "        n = len(index)\n",
    "        for i in range(n):\n",
    "            idx = index[i]\n",
    "            val = nums[i]\n",
    "            length = len(target)\n",
    "            if idx >= length or length == 0:\n",
    "                target.append(val)\n",
    "            else:\n",
    "                tmp = []\n",
    "                for j in range(idx):\n",
    "                    tmp.append(target[j])\n",
    "                tmp.append(val)\n",
    "                for j in range(idx,length):\n",
    "                    tmp.append(target[j])\n",
    "                target = tmp\n",
    "        return target\n",
    "        '''\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def createTargetArray(self, nums: List[int], index: List[int]) -> List[int]:\n",
    "        result=[]\n",
    "        for i in range(len(nums)):\n",
    "            result.insert(index[i],nums[i])\n",
    "        return result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def createTargetArray(self, nums: List[int], index: List[int]) -> List[int]:\n",
    "        ret = []\n",
    "        for i in range(len(nums)):\n",
    "            ret.insert(index[i], nums[i])\n",
    "        return ret"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def createTargetArray(self, nums: List[int], index: List[int]) -> List[int]:\n",
    "        res = []\n",
    "        for num, i in zip(nums, index):\n",
    "            res.insert(i, num)\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def createTargetArray(self, nums: List[int], index: List[int]) -> List[int]:\n",
    "        target = []\n",
    "        for i,j in zip(nums,index):\n",
    "            target.insert(j,i)\n",
    "        return target"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def createTargetArray(self, nums: List[int], index: List[int]) -> List[int]:\n",
    "        c = []\n",
    "        for i in range(len(nums)):\n",
    "           \n",
    "                c.insert(index[i],nums[i])\n",
    "          \n",
    "        return c\n",
    "\n",
    "         "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def createTargetArray(self, nums: List[int], index: List[int]) -> List[int]:\n",
    "        target = [] * len(nums)\n",
    "        for i, j in enumerate(index):\n",
    "            target.insert(j, nums[i])\n",
    "        return target\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def createTargetArray(self, nums: List[int], index: List[int]) -> List[int]:\n",
    "        target=[]\n",
    "        for i in range(len(index)):\n",
    "            target.insert(index[i],nums[i])\n",
    "        return target\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def createTargetArray(self, nums: List[int], index: List[int]) -> List[int]:\n",
    "        target=[]\n",
    "        for i in range(len(nums)):\n",
    "            if index[i]>=len(target):\n",
    "                target.append(nums[i])\n",
    "            else:\n",
    "                target=target[0:index[i]]+[nums[i]]+target[index[i]:len(target)]\n",
    "        return target"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def createTargetArray(self, nums: List[int], index: List[int]) -> List[int]:\n",
    "        for i in range(len(index)):\n",
    "            for j in range(i):\n",
    "                if index[j] >= index[i]:\n",
    "                    index[j] += 1\n",
    "        x = [0]*len(nums)\n",
    "        for i in range(len(index)):\n",
    "            x[index[i]] = nums[i]\n",
    "        return x\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def createTargetArray(self, nums: List[int], index: List[int]) -> List[int]:\n",
    "        r=[]\n",
    "        for i in range(len(index)):            \n",
    "            r.insert(index[i],nums[i])\n",
    "        return r"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def createTargetArray(self, nums: List[int], index: List[int]) -> List[int]:\n",
    "        ans=[]\n",
    "        for i in range(len(nums)):\n",
    "            ans.insert(index[i],nums[i])\n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def createTargetArray(self, nums: List[int], index: List[int]) -> List[int]:\n",
    "        \n",
    "        ret = []\n",
    "        for i in range(len(nums)):\n",
    "            ret.insert(index[i], nums[i])\n",
    "        return ret"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def createTargetArray(self, nums: List[int], index: List[int]) -> List[int]:\n",
    "        target = []\n",
    "        for i in range(len(nums)):\n",
    "            target.insert(index[i], nums[i])\n",
    "        return target"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def createTargetArray(self, nums: List[int], index: List[int]) -> List[int]:\n",
    "        ans = []\n",
    "        for i in range(len(nums)):\n",
    "            ans.insert(index[i], nums[i])\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def createTargetArray(self, nums: List[int], index: List[int]) -> List[int]:\n",
    "        target = []\n",
    "        for i in range(len(nums)):\n",
    "            target.insert(index[i],nums[i])\n",
    "        return target"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def createTargetArray(self, nums: List[int], index: List[int]) -> List[int]:\n",
    "        target = []\n",
    "        for i in range(len(nums)):\n",
    "            target.insert(index[i], nums[i])\n",
    "        return target\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def createTargetArray(self, nums: List[int], index: List[int]) -> List[int]:\n",
    "        target = [] # 创建空列表\n",
    "        for i in range(len(index)): # 遍历列表(也可是nums)\n",
    "            target.insert(index[i],nums[i]) \n",
    "            # insert是一个内置函数，用于在指定索引后面插入对象，参数1是索引，参数2是需要插入的对象。\n",
    "        return target # 返回数组"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def createTargetArray(self, nums: List[int], index: List[int]) -> List[int]:\n",
    "        target = []\n",
    "        res = []\n",
    "        x = len(index)\n",
    "        for i in range(x):\n",
    "            if len(target) == index[i]:\n",
    "                target.append(nums[i])\n",
    "            else:\n",
    "                res = target[index[i]: ]\n",
    "                target = target[:index[i]] + [nums[i]] + res\n",
    "        return target\n",
    " # res.insert(i, a)将a插入到i位置，后面的数字往后移\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def createTargetArray(self, nums: List[int], index: List[int]) -> List[int]:\n",
    "        target=[]\n",
    "        for i in range(len(nums)):\n",
    "            target.insert(index[i],nums[i])\n",
    "        return target"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def createTargetArray(self, nums: List[int], index: List[int]) -> List[int]:\n",
    "        target = []\n",
    "        for i in range(len(index)):\n",
    "            target.insert(index[i], nums[i])\n",
    "        return target"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def createTargetArray(self, nums: List[int], index: List[int]) -> List[int]:\n",
    "        target = []\n",
    "        n = len(index)\n",
    "        for i in range(n):\n",
    "            idx = index[i]\n",
    "            val = nums[i]\n",
    "            length = len(target)\n",
    "            if idx >= length or length == 0:\n",
    "                target.append(val)\n",
    "            else:\n",
    "                tmp = []\n",
    "                for j in range(idx):\n",
    "                    tmp.append(target[j])\n",
    "                tmp.append(val)\n",
    "                for j in range(idx,length):\n",
    "                    tmp.append(target[j])\n",
    "                target = tmp\n",
    "        return target\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def createTargetArray(self, nums: List[int], index: List[int]) -> List[int]:\n",
    "        for i in range(len(index)):\n",
    "            for j in range(i):\n",
    "                if index[j] >= index[i]:\n",
    "                    index[j] += 1\n",
    "        x = [0]*len(nums)\n",
    "        for i in range(len(index)):\n",
    "            x[index[i]] = nums[i]\n",
    "        return x\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def createTargetArray(self, nums: List[int], index: List[int]) -> List[int]:\n",
    "        result=[]\n",
    "        for i in range(len(nums)):\n",
    "            result.insert(index[i],nums[i])\n",
    "        return result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def createTargetArray(self, nums: List[int], index: List[int]) -> List[int]:\n",
    "        target=[]\n",
    "        for i in range(len(nums)):\n",
    "            target.insert(index[i],nums[i])\n",
    "        return target"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def createTargetArray(self, nums: List[int], index: List[int]) -> List[int]:\n",
    "        n = len(nums)\n",
    "        res = list()\n",
    "\n",
    "        for i in range(n):\n",
    "            res = res[0:index[i]] + nums[i:i+1] + res[index[i]:]\n",
    "\n",
    "        return res\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def createTargetArray(self, nums: List[int], index: List[int]) -> List[int]:\n",
    "        \n",
    "        target=[]\n",
    "        for n,i in zip(nums,index):\n",
    "            target.insert(i,n)\n",
    "\n",
    "        return target"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def createTargetArray(self, nums: List[int], index: List[int]) -> List[int]:\n",
    "        ret = []\n",
    "        for i in range(len(nums)):\n",
    "            ret.insert(index[i], nums[i])\n",
    "        return ret\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def createTargetArray(self, nums: List[int], index: List[int]) -> List[int]:\n",
    "        result = []\n",
    "        for num, i in zip(nums, index):\n",
    "            result.insert(i, num)\n",
    "        return result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def createTargetArray(self, nums: List[int], index: List[int]) -> List[int]:\n",
    "        arr = []\n",
    "        for k, v in enumerate(index):\n",
    "            arr.insert(v, nums[k])\n",
    "        \n",
    "        return arr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def createTargetArray(self, nums: List[int], index: List[int]) -> List[int]:\n",
    "        short = min(len(nums),len(index))\n",
    "        target = []\n",
    "        for i in range(short):\n",
    "            target.insert(int(index[i]),nums[i])\n",
    "        return target"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def createTargetArray(self, nums: List[int], index: List[int]) -> List[int]:\n",
    "        target = []\n",
    "        for num, idx in zip(nums, index):\n",
    "            target.insert(idx, num)\n",
    "        return target"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def createTargetArray(self, nums: List[int], index: List[int]) -> List[int]:\n",
    "        target = []\n",
    "        for n, i in zip(nums, index):\n",
    "            target = target[:i] + [n] + target[i:]\n",
    "        return target\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def createTargetArray(self, nums: List[int], index: List[int]) -> List[int]:\n",
    "        target = []\n",
    "        length = len(nums)\n",
    "        for i in range(length):\n",
    "            target.insert(index[i], nums[i])\n",
    "        return target"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def createTargetArray(self, nums: List[int], index: List[int]) -> List[int]:\n",
    "        res = []\n",
    "        for i, v in zip(nums, index):\n",
    "            res.insert(v, i)\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def createTargetArray(self, nums: List[int], index: List[int]) -> List[int]:\n",
    "        target = []\n",
    "        for i in range(len(nums)):\n",
    "            target = target[:index[i]] + [nums[i]] + target[index[i]:]\n",
    "            #print(target)\n",
    "        return target"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def createTargetArray(self, nums: List[int], index: List[int]) -> List[int]:\n",
    "        res = []\n",
    "\n",
    "        for i in range(len(nums)):\n",
    "            res.insert(index[i], nums[i])\n",
    "\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def createTargetArray(self, nums: List[int], index: List[int]) -> List[int]:\n",
    "        ret = []\n",
    "        for i in range(len(nums)):\n",
    "            ret.insert(index[i], nums[i])\n",
    "        return ret\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def createTargetArray(self, nums: List[int], index: List[int]) -> List[int]:\n",
    "        l,out = len(nums),[]\n",
    "        for i in range(l):\n",
    "            out.insert(index[i],nums[i])\n",
    "        return out"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def createTargetArray(self, nums: List[int], index: List[int]) -> List[int]:\n",
    "\n",
    "        n=len(nums)\n",
    "        target = []\n",
    "        for i in range(n):\n",
    "            target.insert(index[i],nums[i])\n",
    "        return target"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def createTargetArray(self, nums: List[int], index: List[int]) -> List[int]:\n",
    "        target = []\n",
    "        for i in range(len(nums)):\n",
    "            target.insert(index[i],nums [i])\n",
    "        return target"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def createTargetArray(self, nums: List[int], index: List[int]) -> List[int]:\n",
    "        target = []\n",
    "        for num, idx in zip(nums, index):\n",
    "            target.insert(idx, num)\n",
    "        return target"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def createTargetArray(self, nums: List[int], index: List[int]) -> List[int]:\n",
    "        ret = []\n",
    "        for i in range(len(nums)):\n",
    "            ret.insert(index[i], nums[i])\n",
    "        return ret\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def createTargetArray(self, nums: List[int], index: List[int]) -> List[int]:\n",
    "        target=[]\n",
    "        for i in range(len(nums)):\n",
    "            a = index[i]\n",
    "            b = nums[i]\n",
    "            target.insert(a,b)\n",
    "        return target"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def createTargetArray(self, nums: List[int], index: List[int]) -> List[int]:\n",
    "        target = []\n",
    "        for i, val in enumerate(index):\n",
    "            target = target[:val] + [nums[i]] + target[val:]\n",
    "        return target\n"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
